package org.lql.chaos.rocketmq.service.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: liangqinglong
 * @date: 2025-08-16 20:19
 * @description: 批量消息生产者
 **/
@Slf4j
@Service
public class BatchProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送批量消息
     *
     * @param topic 主题
     * @param tag   标签
     * @param msgs  消息列表
     */
    public void sendBatchMessage(String topic, String tag, List<String> msgs) {
        String destination = topic + ":" + tag;
        log.info("发送批量消息，数量：{}", msgs.size());
        SendResult sendResult = rocketMQTemplate.syncSend(destination, msgs, 60000);
        log.info("批量消息发送结果：{}", sendResult);
    }
}